﻿using EMall.IdentityService.PermissionGrants;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace EMall.IdentityService.Menus
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class MenuController : ControllerBase
    {
        private readonly IMenuAppService _menuAppService;
        public MenuController(IMenuAppService menuAppService)
        {
            _menuAppService = menuAppService;
        }
        [HttpPost]
        public async Task CreateAsync(CreateMenuDto input)
        {
            await _menuAppService.CreateAsync(input);
        }
        [HttpPut]
        public async Task UpdateAsync(UpdateMenuDto input)
        {
            await _menuAppService.UpdateAsync(input);
        }
        [HttpDelete]
        public async Task DeleteAsync(DeleteMenuDto input)
        {
            await _menuAppService.DeleteAsync(input);
        }
        [HttpGet]
        public async Task<MenuDto> GetAsync(int id)
        {
            return await _menuAppService.GetAsync(id);
        }
        [HttpGet]
        public async Task<IEnumerable<MenuListDto>> GetListAsync([FromQuery] GetMenuListQueryDto input)
        {
            return await _menuAppService.GetListAsync(input);
        }
        [HttpGet]
        public async Task<IPagedList<MenuListDto>> GetPagedListAsync([FromQuery] GetMenuListPagingAndSortingQueryDto input)
        {
            return await _menuAppService.GetPagedListAsync(input);
        }
        [HttpGet]
        [AllowAnonymous]
        public async Task<MenuTree> GetTreeAsync([FromQuery] GetTreeQueryDto input)
        {
            return await _menuAppService.GetTreeAsync(input);
        }
    }
}
